package com.navinfo.platform.trip.common.arithmetic;

import com.navinfo.platform.trip.common.arithmetic.data.OuterStatisticData;
import com.navinfo.platform.trip.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.platform.trip.common.arithmetic.var.VarCoastFlameout_DFN;
import com.navinfo.platform.trip.common.util.CommonUtils;

import java.util.List;

/**
 * 东风新熄火滑行算法<br/>
 * 依赖{@link Mileage}里程油耗算法<br/>
 * 输出：统计、事件<br/>
 * @author web
 * @date: 2020-08-20
 */
public class CoastFlameout_DFN extends AbstractArithmetic<VarCoastFlameout_DFN> {

    @Override
    public void calculate() {
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {
        int sum = 0; //熄火滑行总次数

        List<Boolean> coastFlameouts = getCommonData().getCoastFlameouts();
        if(CommonUtils.isCollectionNotEmpty(coastFlameouts)){
            //累积熄火滑行次数
            int times = 0;
            boolean preStatus = false;
            for(int i=0,size=coastFlameouts.size(); i < size; i++){
                Boolean status = coastFlameouts.get(i);

                //当前点为熄火滑行
                if(status){
                    ++times;
                }
                //当前点不为熄火滑行
                else{
                    //累积三个熄火滑行状态，之后不为熄火滑行次数+1
                    if(preStatus && times>=3){
                        ++sum;
                    }

                    //清空累积状态
                    times = 0;
                }

                preStatus = status;

                //行程结束时要清理对应的未结束事件
                if (i==size-1 && times>=3) {
                    ++sum;
                }
            }
        }

        statisticDataOut.setFlameoutCoastNumber_DF(sum);
    }
}
